import java.lang.Thread;
import java.lang.Math;

public class Test8 {
    public static void main(String[] args) {

        PrimeNum p1 = new PrimeNum();

        p1.start();

        Print p2 = new Print();

        new Thread(p2).start();

    }
}

class PrimeNum extends Thread {  //判断素数
    public void run() {
        for (int i = 2; i <= 100; i++) {
            boolean flag = this.IsPrime(i);
            if (flag == true) {
//                System.out.println("线程1: " + i);
                System.out.println(Thread.currentThread().getName() + ": " + i);
            }

            try {
                int sleepTime = (int)(Math.random() * 1000);
                Thread.sleep(sleepTime);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    public boolean IsPrime(int num) {
        for (int i = 2; i < Math.sqrt(num); i++) {
            if (num % i == 0) {
                return false;
            }
        }

        return true;
    }
}

class Print implements Runnable {
    public void run() {
        for (int i = 20; i >= 1; i--) {
//            System.out.println("线程2: " + i);
            System.out.println(Thread.currentThread().getName() + ": " + i);
            try {
                int sleepTime = (int)(Math.random() * 1000);
                Thread.sleep(sleepTime);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}